﻿using System;
using System.Collections.Generic;
using System.Web.Services;
using Monkey.Warrenty.Biz;
using Monkey.Warrenty.Constants;
using MonkeyWarranty.Web.Common;

namespace MonkeyWarranty.Web.WarrantyTickets
{
    public partial class LendProducts : System.Web.UI.Page
    {
        #region Properties

        private static WarrantyProductBiz _warrantyProductBiz;

        private static WarrantyProductBiz WarrantyProductManager
        {
            get { return _warrantyProductBiz ?? (_warrantyProductBiz = new WarrantyProductBiz()); }
        }

        #endregion

        protected void Page_Load(object sender, EventArgs e)
        {
            if (WarrantyCommon.CurrrentEmployee == null)
            {
                Response.Redirect("~/Logon.aspx");
                return;
            }

            if (!WarrantyCommon.CurrrentEmployee.HasRole(RoleConstant.AdminBaoHanh))
            {
                Response.Redirect("~/NoPermission.aspx");
            }
        }

        [WebMethod(EnableSession = true)]
        public static object TicketProductList(int jtStartIndex, int jtPageSize, string jtSorting)
        {
            var ticketCount = WarrantyProductManager.GetLendProductsCount();
            var products = WarrantyProductManager.GetLendProducts(jtStartIndex, jtPageSize, jtSorting);
            return new { Result = "OK", Records = products, TotalRecordCount = ticketCount };
        }

        [WebMethod(EnableSession = true)]
        public static object ReceivedBack(List<long> productIds)
        {
            WarrantyProductManager.ReceivedBack(productIds);
            return new { Result = "OK" };
        }
    }
}